import 'package:XinXiZiXun/common/entitys/entitys.dart';
import 'package:XinXiZiXun/common/utils/utils.dart';
import 'package:XinXiZiXun/common/values/values.dart';
import 'package:XinXiZiXun/gen_a/A.dart';
import 'package:flutter/material.dart';

class HeaderLayout extends StatefulWidget {
  @override
  _HeaderLayoutState createState() => _HeaderLayoutState();
}

class _HeaderLayoutState extends State<HeaderLayout> {
  UserResult profile;

  //获取用户信息
  _handleReadProfile() async {
    dynamic result =
        await StorageUtil().getJson(Service.STORAGE_USER_PROFILE_KEY);
    profile = UserResult.fromMap(result);
    print('用户信息----:${profile}');
  }

  @override
  void initState() {
    _handleReadProfile();

    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Container(
//      margin: EdgeInsets.only(bottom: kDefaultPadding * 2.5),
      height: duSetHeight(240),
//      color: AppColors.primaryBlackColor,
      child: Stack(
        children: [
          Container(
            padding: EdgeInsets.only(
              left: duSetWidth(ktDefaultPadding),
              right: duSetWidth(ktDefaultPadding),
              bottom: duSetHeight(60),
            ),
            height: duSetHeight(200),
            decoration: BoxDecoration(
              color: AppColors.primaryElementColor,
              //底部圆角
//              borderRadius: BorderRadius.only(
//                bottomLeft: Radius.circular(36),
//                bottomRight: Radius.circular(36),
//              ),
            ),
            child: Row(
              children: [
                InkWell(
                  child: Container(
                    width: duSetWidth(2 * ksDefaultPadding),
                    height: duSetWidth(2 * ksDefaultPadding),
                    decoration: BoxDecoration(
                        shape: BoxShape.circle,
                        image: DecorationImage(
                          image: (profile != null
                              ? NetworkImage(profile.avatarUrl)
                              : AssetImage(A.assets_images_img_user_touxaing)),
                          fit: BoxFit.cover,
                        )),
                  ),
                  onTap: () {
                    print('点击了头像');
                  },
                ),
                Padding(
                  padding: EdgeInsets.fromLTRB(duSetWidth(ktDefaultPadding), 0,
                      duSetWidth(kDefaultPadding), 0),
                  child: Text(
                    profile != null ? profile.phone : '昵称',
                    overflow: TextOverflow.clip,
                    style: TextStyle(
                      color: AppColors.primaryBackgroundColor,
                      fontFamily: 'Avenir',
                      fontSize: duSetScaleFontSize(36.0),
                      fontWeight: FontWeight.w500,
                    ),
                  ),
                ),
              ],
            ),
          ),
          Positioned(
            left: duSetWidth(ktDefaultPadding),
            right: duSetWidth(ktDefaultPadding),
            bottom: duSetHeight(10),
            child: InkWell(
              onTap: () {
                print('点击系统设置');
                Navigator.of(context).pushNamed('/systempage');
              },
              child: Container(
                height: duSetHeight(80),
                decoration: BoxDecoration(
                  color: AppColors.primaryBackgroundColor,
                  borderRadius: BorderRadius.circular(kDefaultPadding),
                ),
                child: Row(
                  children: [
                    Padding(
                      padding: EdgeInsets.only(
                        left: duSetWidth(ktDefaultPadding),
                        top: duSetHeight(0),
                      ),
                      child: Image.asset(A.assets_images_ic_user_shezhi),
                    ),
                    Padding(
                      padding: EdgeInsets.only(
                        left: duSetWidth(10),
                        right: duSetWidth(10),
                      ),
                      child: Text(
                        '系统设置',
                        style: TextStyle(
                          fontFamily: 'Avenir',
                          fontSize: duSetScaleFontSize(28.0),
                          fontWeight: FontWeight.w500,
                          color: AppColors.primaryBlackColor,
                        ),
                      ),
                    ),
                    Spacer(),
                    Padding(
                      padding: EdgeInsets.only(
                        right: duSetWidth(ktDefaultPadding),
                      ),
                      child: Image.asset(A.assets_images_ic_user_jiantou),
                    ),
                  ],
                ),
              ),
            ),
          ),
        ],
      ),
    );
  }
}
